package LuoGu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class P1102Other {
    public static void main(String[] args) throws Exception{
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        String[] tmps=in.readLine().split(" ");
        int n=Integer.valueOf(tmps[0]),c=Integer.valueOf(tmps[1]);
        tmps=in.readLine().split(" ");
        long res=0;
        //key为输入数据	value为数据个数
        Map<Integer, Long> map=new HashMap<>();
        for (int i = 0; i < tmps.length; i++) {
            int key=Integer.valueOf(tmps[i]);
            if(map.containsKey(key)) {
                map.put(key, map.get(key)+1);
            }else {
                map.put(key, 1L);
            }
        }
        int[] data=new int[map.size()];
        int index=0;
        for (Map.Entry<Integer, Long> entry : map.entrySet()) {
            data[index]=entry.getKey();
            index++;
        }
        Arrays.sort(data);
        for (int i = 0; i < data.length; i++) {
            int target=data[i]+c;
            index=Arrays.binarySearch(data, target);
            if(index>0) res+=map.get(data[index])*map.get(data[i]);
        }
        System.out.println(res);
        in.close();
    }

}
